import React, {Component} from 'react'
import {View, Text, TextInput, TouchableOpacity,Image} from 'react-native'
import {PostFeedbackApi} from '../../config/api'
import styles from '../../config/styles'
import {connect} from 'react-redux'
import {changeRole} from '../../redux/actions/user'
import { NavigationActions } from 'react-navigation'

class SwichRole extends Component {
    constructor (props) {
        super(props)
        this.state = {
        }
    }


    changeRole = (status) => {
        this.props.dispatch(changeRole(status));
        this.props.navigation.dispatch({
            type: NavigationActions.NAVIGATE,
            routeName: 'homework_index',
            action: {
                type: NavigationActions.RESET,
                index: 0,
                actions: [{type: NavigationActions.RESET, routeName: 'homework_index'}]
            }
        })

        //const resetAction = NavigationActions.reset({
        //    index: 0,
        //    actions: [
        //        NavigationActions.navigate({routeName:'homework_index'})//要跳转到的页面名字
        //    ]
        //})
        //this.props.navigation.dispatch(resetAction)
    }

    render () {
        const {navigation} = this.props

        return (
            <View style={styles.main_body}>

                <View style={{backgroundColor:'white',flexDirection: 'row'}}>

                    <TouchableOpacity onPress={() => this.changeRole(false)} style={{flex:1,justifyContent: 'center',alignItems: 'center',padding:15}}><Image style={{height: 100, width: 100, borderRadius: 50}} source={require('../../assets/images/role-teacher-active.png')}></Image><Text style={{marginTop:15,fontSize:18}}>老师</Text></TouchableOpacity>
                    <TouchableOpacity onPress={() => this.changeRole(true)} style={{flex:1,justifyContent: 'center',alignItems: 'center',padding:15}}><Image style={{height: 100, width: 100, borderRadius: 50}} source={require('../../assets/images/role-teacher-female.png')}></Image><Text style={{marginTop:15,fontSize:18}}>组长</Text></TouchableOpacity>

                </View>

            </View>
        )
    }
}
const mapStateToProps = (state) => {
    return {
        user: state.user,
        isLeader:state.isLeader
    }
}

export default connect(mapStateToProps)(SwichRole)